import Mock from 'mockjs'

Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/institutions/list`, 'post', () => {
    let list = Mock.mock({
        'list|10': [
            {
                title: '@ctitle()',
                value: '@id',
                key: '@id',
                'children|10': [
                    {
                        title: '@ctitle()',
                        value: '@id',
                        key: '@id',
                    }
                ]
            }
        ]
    }).list;
    return {
        list,
    }
})
Mock.Random.extend({
    phone: function () {
        var phonePrefixs = ['132', '135', '189'] // 自己写前缀哈
        return this.pick(phonePrefixs) + Mock.mock(/\d{8}/) //Number()
    }
})

Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/institutions/table`, 'post', (request) => {
    let {page, pageSize} = JSON.parse(request.body),
        total = 94,
        list = [],
        num = parseInt(total/ pageSize) >= page ? pageSize : total - (pageSize * (page - 1));
    for(let item = 0; item < num; item++) {
        list.push(Mock.mock({
            id: '@id',
            username: '@cname()',
            contact: '@cname()',
            'phone': '@phone',
            "state|1-2": true,
            institutions: '@csentence',
        }))
    }
    return {
        list, total
    }
})